﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace cmsservice.DAL
{
    public class StockWeatherDAL
    {
        private StockWeatherDAL() { }
        private static volatile StockWeatherDAL single = null;
        
        private static object locker = new object();
        /// <summary>
        /// 获取实例
        /// </summary>
        /// <returns></returns>
        public static StockWeatherDAL StockWeatherInstance()
        {
            if (single == null)
            {
                lock (locker)
                {
                    if (single == null)
                    {
                        single = new StockWeatherDAL();
                    }
                }
            }
            return single;
        }

        delegate DataTable StockWeather(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters);
        StockWeather instance = new StockWeather(SqlHelper.ExecuteGetTable);
        /// <summary>
        /// 得到天气预报
        /// </summary>
        /// <returns></returns>
        public DataRow GetStockWeather()
        {
            string sql = "select top 1 cast(date as bigint) as date,weather,[content],posi,short_strategy,long_strategy from dbo.WEATHER_FORECAST order by date desc";
            DataTable tb = instance(DBConn.qgqp2, CommandType.Text, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0];
            }
            else
            {
                return null;
            }
        }
    }
}
